﻿@{
    ViewBag.Title = "SearchSongSinger";
    Layout = "~/Views/Shared/_LayoutPublic.cshtml";
}
    <link href="@Url.Content("../../Styles/Playlist/popbox.css")" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/Playlist/popbox.js" type="text/javascript"></script>
    <link href="@Url.Content("../../Styles/SongDetails.css")" rel="stylesheet" type="text/css" />    
 <script type='text/javascript' charset='utf-8'>
     $(document).ready(function () {
         $('.popbox').popbox();
     });
     
     </script>
   
     <script type="text/javascript">
         function getID(id) {
            
             var playlistname = document.getElementById(id).value;
            
             $.ajax({
                 url: '/playlist/addplaylist',
                 dataType: 'json',
                 type: "post",
                 data: ({ 'playlistname': playlistname }),
                 success: function (result) {
                     location.reload();
                 }
             });
         }
         function addMusic(songid) {
         var plid = $("#cbx-playlist-name").val();
         if (plid != "") {
             var ans = window.confirm("Bạn chắc chắn muốn thêm bài hát này vào danh sách?");
             if (ans) {
                 $.ajax({
                     url: '/playlist/addmusic',
                     dataType: 'json',
                     type: 'post',
                     data: ({ 'songid': songid, 'plid': plid }),
                     success: function (result) {

                     }
                 });
             } 
         }         
     }
  </script>
 

<div class="content-song">   
    <div id="content-details">
<ul>
    @{
        List<ListenMusic.Song_ServiceReference.SongSinger > lst_songSinger  = ViewBag.songSinger ;
        List<ListenMusic.Playlist_ServiceReference.FavoritePlayList> lst_favaritesPlaylist = ViewBag.songInPlaylist;
      }
    @for(int i = 0; i <  lst_songSinger.Count(); i++)
    { 
        <li class="fm">
            @Html.ActionLink( lst_songSinger[i].SongName, "ListenPage", "Listen", new { songid =  @lst_songSinger[i].SongID, pageindex = 1 },null)  <br />
            <span class="sub-detail">
                Trình bày: <a class="singer" href="#">@lst_songSinger[i].SingerName</a> | Lượt nghe: @lst_songSinger[i].CountView
            </span>
            <div class='popbox'>                
                @if (Session["user"] == null)   
                {
                    <a href="#login-box" class="login-window">
                    <img src='../../Images/Icons/add.png' alt="" width="14px" title="Thêm vào danh sách yêu thích" style='position:relative' />
                    </a>                      
                }
                else
                {
                    bool flag = true;
                    for (int j = 0; j < lst_favaritesPlaylist.Count(); j++)
                    {
                        if (lst_favaritesPlaylist[j].SongID.Equals(lst_songSinger[i].SongID))
                        {
                            <a class='open1' href='#'>
                                <img src='../../Images/Icons/check.png' alt="" style='width:14px;position:relative' />
                            </a>  
                            flag = false;
                            break;
                        }
                    }
                    if (flag == true)
                    {
                        <a class='open' href="#">
                            <img src='../../Images/Icons/add.png' alt=""  title="Thêm vào danh sách yêu thích" style='width:14px;position:relative' />
                        </a>                       
                    }
                }
                <a href="@Url.Action("dowloadfile", "dowload", new { url = lst_songSinger[i].SongURL })"><img src="../../Images/Icons/download.jpg" title="Tải bài hát về máy" width="16" height="16px" alt="" /></a>    
                <div class='collapse'>
                      <div class='box'>
                        <div class='arrow'></div>
                        <div class='arrow-border'></div>
                        <form action="" method="post" id="subForm">
                            <div style="margin-left:20px; margin-top:10px">
                                <select id="cbx-playlist-name" name="cbx-playlist-name" onchange="addMusic(@lst_songSinger[i].SongID)">
                                    <option value="">-Chọn-</option>
                                        @if (@Session["user"] != null)
                                        {
                                            foreach (ListenMusic.Playlist_ServiceReference.Playlist pl in ViewBag.playlist)
                                            {
			                                    <option value='@pl.PlaylistID'>@pl.PlaylistName</option>
                                            }
                                        }
                                </select>
                            </div>
                            <div style="margin-left:20px">
                                <input type="text" id="playlistname-@lst_songSinger[i].SongID" name="playlistname" placeholder="Tên của laylist" style="width:90px; margin-top:10px;" /> 
                                <a href="#" id="create-playlist" onclick="getID('playlistname-@lst_songSinger[i].SongID')" style="font-size:small" >Tạo Playlist</a>
                            </div>
                          <div style="text-align:center; margin-top:10px"><a href="#" class="close">Cancel</a></div>
                        </form>
                      </div>
                    </div>
                </div>
       </li>       
    }
</ul> 
</div>
    <div class="page_number">
        Trang:
        @for (int i = 1; i <= ViewBag.total; i++)
        { 
            <a href="/song/SearchSong_bySinger?pageindex=@i&singerid=@ViewBag.singerid">@i</a>
        }
    </div>
</div>
